package com.demo.config.mq.handler;

import com.google.common.collect.Maps;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@Slf4j
public class TgBotOneDelayConfig {

  /**
   * 延迟队列
   */
    @Bean
    public Queue botOneDelayQueue() {
        return new Queue(TgBotOneMqConsts.BOT_ONE_DELAY_QUEUE, true);
    }

    /**
     * 延迟队列交换器, x-delayed-type 和 x-delayed-message 固定
     */
    @Bean
    public CustomExchange botOneDelayExchange() {
        Map<String, Object> args = Maps.newHashMap();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(TgBotOneMqConsts.BOT_ONE_DELAY_MODE_QUEUE, "x-delayed-message", true, false, args);
    }

    /**
     * 延迟队列绑定自定义交换器
     *
     * @param botOneDelayQueue    队列
     * @param botOneDelayExchange 延迟交换器
     */
    @Bean
    public Binding orderCloseDelayBinding(Queue botOneDelayQueue, CustomExchange botOneDelayExchange) {
        return BindingBuilder.bind(botOneDelayQueue).to(botOneDelayExchange).with(
            TgBotOneMqConsts.BOT_ONE_DELAY_QUEUE).noargs();
    }

}
